<?php
namespace app\app\controller;

use think\Controller;

class Product extends Controller {
    /*
     * 全部商品信息
     */
    public function all() {
        $ret = model('AppProductInfo')->select();
        return $ret;
    } 
    
    /*
     * 单个商品信息
     */
    public function single($id) {
        $ret = model('AppProductInfo')->get(['id'=>$id]);
        return $ret;
    }
    
    /*
     * 单个商品购买生成的<报表>中的订单信息
     */
    public function buy($id, $username, $orderId) {
        $appUserInfo = model('AppUserInfo')->get(['username'=>$username]);
        $ret = model('AppProductInfo')->get(['id'=>$id]);
        $randCode = mt_rand(1000, 9999);
        $orderInfo = [
            'username'    => $username,
            'order_id'    => $orderId,
            'image'       => '1',
            'title'       => '收款成功',
            'title_color' => 'green',
            'money'       => $ret->price,
            'bis_name'    => $appUserInfo->bis_name,
            'bis_id'      => $appUserInfo->bis_id,
        ];
        $AppBisOrderId = model('AppBisOrder')->add($orderInfo);
        if($AppBisOrderId) {
            return 4500;
        } else {
            return 4502;
        }
    }
}
